package studentsOffice;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import degreeAndSyllabus.EnrolledInDegree;
import degreeAndSyllabus.SubjectInPlan;
/**
 * 
 * @author Maria Laura Medici
 *
 */

public class AcademicPaper {
	
	/* ******************************** Variables ******************************** */
	private EnrolledInDegree student;
    private Map<SubjectInPlan,Integer> materias = new HashMap<SubjectInPlan,Integer>();
	
	/* ******************************* Constructor ******************************* */
	public AcademicPaper( EnrolledInDegree student){
		this.student = student;
		this.materias = this.student.getMateriasCursadas();
	}
	
	/* ******************************** Get & Set ******************************** */
	public void setStudent( EnrolledInDegree student) {
		this.student = student;
	}

	public  EnrolledInDegree getStudent() {
		return student;
	}
	
	public Map<SubjectInPlan,Integer> getMaterias() {
		return materias;
	}


	public void setMaterias(Map<SubjectInPlan,Integer> materias) {
		this.materias = materias;
	}


	/* ********************************* Metodos ********************************* */
	

/**
 * Consulta la nota de una materia
 */
	public int consultNoteSubject(SubjectInPlan materia){
		return this.getMaterias().get(materia);
	
	}
	
	/**
	 *   Calcula el coeficiente de un alumno, promedio es la sumatoria de notas 
	 *   (incluyendo los aplazos) / cantidad de materias con cursada,
	 *   tcc son los creditos y tcf son  los creditos restantes
	 */
	public int calculateCoefficient(){
	  int promedio = this.sumaNotas()/this.getMaterias().size();//
	  int tcc = this.getStudent().getCreditosActuales(); //creditos
	  int tcf = (this.getStudent().getRefDegree().getCreditosRequeridos())- (this.getStudent().getCreditosActuales()); //creditos faltan
	  return (promedio/2) + ((tcc - tcf) / tcc)*5;
	}

	/**
	 * Devuelve la suma de todas las notas 
	 * 
	 */
	public Integer sumaNotas(){
		int suma = 0;
		Iterator<Integer> notas = this.getMaterias().values().iterator();
		while( notas.hasNext()){
			if(notas.next()!= -1){
		    suma = suma + notas.next();
            notas.remove();}
		}
		return  suma;
	}
}
